<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <!-- <form action="getPost" method="post">
        <input type="text" name="aa">
        <input type="text" name="bb">
        <input type="submit" value="提交">
    </form> -->
    <input type="text" id="aa">
    <input type="text" id="bb">
    <input type="button" id="submit" value="提交">    

    <script>
        let button = document.querySelector("#submit");
        let a = document.querySelector("#aa");
        let b = document.querySelector("#bb");
        button.onclick = function() {
            $.ajax({
                type:'post',
                url:'getPost2',
                contentType:'application/json',
                data:JSON.stringify({
                    aa: a.value,
                    bb: b.value
                }),
                success: function(body) {
                    console.log(body);
                }
            });
        }
    </script>
</body>
</html>